#include <gtest/gtest.h>
#include "../vas_config.h"

using namespace vas;

TEST(ConfigTest, JsonToChannel) {
    std::string channel_str = "    {\n"
                              "      \"channel\": \"test.mp4\",\n"
                              "      \"url\": \"/opt/test.mp4\",\n"
                              "      \"tasks\": [\n"
                              "        {\n"
                              "          \"type\": \"HUMAN-DETECTION\",\n"
                              "          \"roi\": [[1,1], [10,10]],\n"
                              "          \"interval\": 10\n"
                              "        }\n"
                              "      ]\n"
                              "    }\n";
    Channel channel = JsonToChannel(StringToJson(channel_str));
    ASSERT_EQ(channel.channel, "test.mp4");
    ASSERT_EQ(channel.url, "/opt/test.mp4");
    ASSERT_EQ(channel.tasks.size(), 1);
    ASSERT_EQ(channel.tasks[0].type, "HUMAN-DETECTION");
    ASSERT_EQ(channel.tasks[0].interval, 10);
    ASSERT_EQ(channel.tasks[0].roi.size(), 2);
    ASSERT_EQ(channel.tasks[0].roi[0].x, 1);
    ASSERT_EQ(channel.tasks[0].roi[0].y, 1);
    ASSERT_EQ(channel.tasks[0].roi[1].x, 10);
    ASSERT_EQ(channel.tasks[0].roi[1].y, 10);
}


TEST(ConfigTest, ReadConfig) {
    std::string config_str = "{\n"
                             "  \"max_videos\": 5,\n"
                             "  \"http_port\": 5034,\n"
                             "  \"http_threads\": 4,\n"
                             "  \"rocket_mq_host\": \"127.0.0.1:9876\",\n"
                             "  \"zookeeper_host\": \"127.0.0.1:2171\",\n"
                             "  \"algorithms\": [\n"
                             "    {\n"
                             "      \"name\": \"SceneRecognition\",\n"
                             "      \"mock\": 0\n"
                             "    }\n"
                             "  ],\n"
                             "  \"local_channels\": [\n"
                             "    {\n"
                             "      \"channel\": \"test.mp4\",\n"
                             "      \"url\": \"/opt/test.mp4\",\n"
                             "      \"tasks\": [\n"
                             "        {\n"
                             "          \"type\": \"HUMAN-DETECTION\",\n"
                             "          \"roi\": [[1,1], [10,10]],\n"
                             "          \"interval\": 10\n"
                             "        }\n"
                             "      ]\n"
                             "    }\n"
                             "  ]\n"
                             "}";
    VasConfig config = ReadConfig(config_str);
    ASSERT_EQ(config.max_videos, 5);
    ASSERT_EQ(config.http_port, 5034);
    ASSERT_EQ(config.http_threads, 4);
    ASSERT_EQ(config.rocket_mq_host, "127.0.0.1:9876");
    ASSERT_EQ(config.zookeeper_host, "127.0.0.1:2171");
    ASSERT_EQ(config.algorithm_mock.size(), 1);
    ASSERT_EQ(config.local_channels.size(), 1);
    ASSERT_EQ(config.algorithm_mock["SceneRecognition"], false);
    ASSERT_EQ(config.local_channels[0].channel, "test.mp4");
    ASSERT_EQ(config.local_channels[0].url, "/opt/test.mp4");
    ASSERT_EQ(config.local_channels[0].tasks.size(), 1);
    ASSERT_EQ(config.local_channels[0].tasks[0].type, "HUMAN-DETECTION");
    ASSERT_EQ(config.local_channels[0].tasks[0].interval, 10);
    ASSERT_EQ(config.local_channels[0].tasks[0].roi.size(), 2);
    ASSERT_EQ(config.local_channels[0].tasks[0].roi[0].x, 1);
    ASSERT_EQ(config.local_channels[0].tasks[0].roi[0].y, 1);
    ASSERT_EQ(config.local_channels[0].tasks[0].roi[1].x, 10);
    ASSERT_EQ(config.local_channels[0].tasks[0].roi[1].y, 10);
}